<?php
/***************************************************************
 *  Copyright notice
 *
 *  (c) 2011 Florian Müller <it-admin@ifp-potsdam.co>, IFP
 *
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/

/**
 * Teilnehmer
 */
class Tx_IfpCurriculum2_Domain_Model_Teilnehmer extends Tx_Extbase_DomainObject_AbstractEntity {

	/**
	 * FEuser
	 *
	 * @var Tx_Extbase_Domain_Model_FrontendUser
	 */
	protected $feuser;

	/**
	 * Ausbildungsschema
	 *
	 * @var Tx_IfpCurriculum2_Domain_Model_Ausbildungsschema
	 */
	protected $ausbildungsschema;

	/**
	 *
	 *Herr/frau
	 *Herr=0
	 *Frau=1
	 *
	 * @var boolean
	 */
	protected $geschlecht;
	/**
	 *
	 * titel
	 * @var string
	 */
	protected $titel;
	/**
	 *
	 * Vorname
	 * @var string
	 * @validate StringLength(minimum=3,maximum=50)
	 */
	protected $vorname;
	/**
	 *
	 * Nachname
	 * @var string
	 * @validate StringLength(minimum=3,maximum=50)
	 */
	protected $nachname;
	/**
	 * Mail
	 * @var string
	 * @validate EmailAddress
	 */
	protected $mail;
	/**
	 * Telefon
	 *
	 * @var string
	 * 
	 */
	protected $telefon;
	/**
	 * Straße Hausnummer
	 * 	 * @var string
	 */
	protected $anschrift;
	/**
	 *
	 * Postleitzahl
	 * @var string
	 *
	 */
	protected $plz;
	/**
	 *
	 * Stadt
	 * @var string
	 */
	protected $stadt;
	/**
	 * anmeldungen
	 * @var Tx_Extbase_Persistence_ObjectStorage<Tx_IfpCurriculum2_Domain_Model_Anmeldung>
	 * 
	  */
	protected $anmeldungen;
	
	
	
	public function __construct() {
		//Do not remove the next line: It would break the functionality
		$this->initStorageObjects();
	}

	/**
	 * Initializes all Tx_Extbase_Persistence_ObjectStorage instances.
	 *
	 * @return void
	 */
	protected function initStorageObjects() {
		/**
		* Do not modify this method!
		* It will be rewritten on each save in the kickstarter
		* You may modify the constructor of this class instead
		*/
		$this->anmeldungen = new Tx_Extbase_Persistence_ObjectStorage();
	}
	/**
	 * @param Tx_IfpCurriculum2_Domain_Model_Ausbildungsschema $ausbildungsschema
	 * @return void
	 */
	public function setAusbildungsschema(Tx_IfpCurriculum2_Domain_Model_Ausbildungsschema $ausbildungsschema) {
		$this->ausbildungsschema = $ausbildungsschema;
	}

	/**
	 * @return Tx_IfpCurriculum2_Domain_Model_Ausbildungsschema
	 */
	public function getAusbildungsschema() {
		return $this->ausbildungsschema;
	}
/**
	 * @param Tx_Extbase_Persistence_ObjectStorage<Tx_IfpCurriculum2_Domain_Model_Anmeldung> $anmeldungen
	 * @return void
	 */
	public function setAnmeldungen(Tx_Extbase_Persistence_ObjectStorage $anmeldungen) {
		$this->anmeldungen = $anmeldungen;
	}

	/**
	 * @return Tx_Extbase_Persistence_ObjectStorage<Tx_IfpCurriculum2_Domain_Model_Anmeldung>
	 */
	public function getAnmeldungen() {
		return $this->anmeldungen;
	}

	/**
	 * @param Tx_IfpCurriculum2_Domain_Model_Anmeldung the Anmeldung to be added
	 * @return void
	 */
	public function addAnmeldungen(Tx_IfpCurriculum2_Domain_Model_Anmeldung $anmeldungen) {
		$this->anmeldungen->attach($anmeldungen);
	}

	/**
	 * @param Tx_IfpCurriculum2_Domain_Model_Anmeldung the Anmeldung to be removed
	 * @return void
	 */
	public function removeAnmeldungen(Tx_IfpCurriculum2_Domain_Model_Anmeldung $anmeldungenToRemove) {
		$this->anmeldungen->detach($anmeldungenToRemove);
	}

	/**
	 *
	 * Enter description here ...
	 * @return boolean
	 */
	public function getGeschlecht()
	{
		return $this->geschlecht;
	}
	/**
	 *
	 * Enter description here ...
	 * @param boolean $value
	 * @return void
	 */
	public function setGeschlecht($geschlecht) {
		$this->geschlecht = $geschlecht;
	}

	/**
	 *
	 * Enter description here ...
	 * @return Tx_Extbase_Domain_Model_FrontendUser
	 */
	public function getFeuser()
	{
		echo "read feuser ";
		return $this->feuser;
	}
	/**
	 *
	 * E
	 * @param Tx_Extbase_Domain_Model_FrontendUser $feuser
	 * @return void
	 */
	public function setFeuser($feuser){
		$this->feuser = $feuser;
	}
	/**
	 *
	 * Enter description here ...
	 * @return string
	 */
	public function getTitel()	{
		if(isset($this->feuser)){
			return $this->feuser->getTitle();
		}
		return $this->titel;
	}
	/**
	 *
	 * Enter description here ...
	 * @param string $titel
	 * @return void
	 */
	public function setTitel($titel) {
		$this->titel = $titel;
	}
	/**
	 *
	 * Enter description here ...
	 * @return string
	 */
	public function getVorname()	{
	if(isset($this->feuser))
			return $this->feuser->getFirstName();
		return $this->vorname;
		
	}
	/**
	 *
	 * Enter description here ...
	 * @param string $vorname
	 * @return void
	 */
	public function setVorname($vorname) {
		$this->vorname = $vorname;
	}
	/**
	 *
	 * Enter description here ...
	 * @return string
	 */
	public function getNachname()	{
		//var_dump($this->feuser);
		if(isset($this->feuser))
			return $this->feuser->getLastName();
		return $this->nachname;
	}
	/**
	 *
	 * Enter description here ...
	 * @param string $nachname
	 * @return void
	 */
	public function setNachname($nachname) {
		$this->nachname = $nachname;
	}
/**
	 *
	 * Enter description here ...
	 * @return string
	 */
	public function getMail()	{
		if(isset($this->feuser))
			return $this->feuser->getEmail();
		return $this->mail;
	}
	/**
	 *
	 * Enter description here ...
	 * @param string $mail
	 * @return void
	 */
	public function setMail($mail) {
		$this->mail = $mail;
	}
/**
	 *
	 * Enter description here ...
	 * @return string
	 */
	public function getTelefon()	{
		if(isset($this->feuser))
			return $this->feuser->getTelephone();
		return $this->telefon;
	}
	/**
	 *
	 * Enter description here ...
	 * @param string $telefon
	 * @return void
	 */
	public function setTelefon($telefon) {
		$this->telefon = $telefon;
	}
/**
	 *
	 * Enter description here ...
	 * @return string
	 */
	public function getAnschrift()	{
		if(isset($this->feuser))
			return $this->feuser->getAddress();
		return $this->anschrift;
	}
	/**
	 *
	 * Enter description here ...
	 * @param string $anschrift
	 * @return void
	 */
	public function setAnschrift($anschrift) {
		$this->anschrift = $anschrift;
	}
/**
	 *
	 * Enter description here ...
	 * @return string
	 */
	public function getPlz()	{
		if(isset($this->feuser))
			return $this->feuser->getZip();
		return $this->plz;
	}
	/**
	 *
	 * Enter description here ...
	 * @param string $plz
	 * @return void
	 */
	public function setPlz($plz) {
		$this->plz = $plz;
	}
/**
	 *
	 * Enter description here ...
	 * @return string
	 */
	public function getStadt()	{
		if(isset($this->feuser))
			return $this->feuser->getCity();
		return $this->stadt;
	}
	/**
	 *
	 * Enter description here ...
	 * @param string $stadt
	 * @return void
	 */
	public function setStadt($stadt) {
		$this->stadt = $stadt;
	}
	/**
	 * 
	 * Liefert vollständigen Namen
	 * 
	 * @return string
	 */
	public function getFullName(){
		if($this->getNachname()==""&&$this->getVorname()==""){
			if(isset($this->feuser))
				return $this->feuser->getUsername();
		}
		$str="";
		$titel=$this->getTitel();
		if (!empty($titel)) {
			$str.=$this->getTitel()." ";
		}
		$str.=$this->getVorname()." ".$this->getNachname();
		if($this->isGast()){
			$str.=" (G)";
		}
		
		return $str;
	}
/**
	 * 
	 * Liefert vollständigen Namen
	 * 
	 * @return string
	 */
	public function getFullName2(){
		if($this->getNachname()==""&&$this->getVorname()==""){
			if(isset($this->feuser))
				return $this->feuser->getUsername();
		}
		$str="";
		$titel=$this->getTitel();
		if (!empty($titel)) {
			$str.=$this->getTitel()." ";
		}
		$str.=$this->getVorname()." ".$this->getNachname();
		
		
		return $str;
	}
	public function isGast(){
		if(isset($this->feuser))
			return false;
		return true;
	}
	
	public function getAnzahlanmeldungen(){
		//var_dump($this->anmeldungen);
		$count=0;
		if(isset($this->anmeldungen)){
			$countArray=$this->getAnmeldungen()->toArray();
			
			foreach ($countArray as $anmeldung) {
				if(!$anmeldung->isStorniert())
				$count++;
			}
		}
		return $count;
		
	}

}
?>